/* 
 * File:   VoxelGrid.h
 * Author: brady
 *
 * Created on August 28, 2011, 9:41 PM
 */

#ifndef VOXELGRID_H
#define	VOXELGRID_H

#include <vector>
#include <acceleration/Voxel.h>
#include <core/Vector3D.h>
#include <acceleration/IntersectionStructure.h>
#include <acceleration/BoundingVolumeHierarchy.h>

using namespace std;

class VoxelGrid : public IntersectionStructure {
public:
    VoxelGrid();
    VoxelGrid(const VoxelGrid& orig);
    virtual ~VoxelGrid();
    void addShape(Shape* shape);
    void finalize();
    IntersectionResult getFirstIntersection(IntersectionParams& ip);
    vector<IntersectionResult> getAllIntersections(IntersectionParams& ip);
    IntersectionResult getAnyIntersection(IntersectionParams& ip);
    BoundingBox getBoundingBox(){return BoundingBox(minCorner, maxCorner);}
private:
    Voxel* getVoxel(Vector3D point);
    vector<Voxel*> getIntersectedVoxels(IntersectionParams& ip);
    Voxel* getNextVoxel(Voxel* curVoxel, IntersectionParams& ip);
    Voxel* getVoxel(int x, int y, int z);
    BoundingVolumeHierarchy holdingStructure;
    Vector3D voxelDimensions;
    int shapeCount;
    int xCount;
    int yCount;
    int zCount;
    Vector3D minCorner;
    Vector3D maxCorner;
    Voxel* *** voxels; //a 3d array of voxel pointers

};

#endif	/* VOXELGRID_H */

